package thread;

import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM2;
import sun.font.FontRunIterator;

/*
 线程的优先级
 线程有十大优先级 分别对应整数1-10. 其中1为最低 10为最高 5为默认值
 线程start（）方法调用后便纳入线程调度器中并发运行 线程只能被动的被分配时间片进行并发
 调度器会尽可能的平均分配时间片
 调整优先级可以最大程度的调整获取时间片的概率  优先级高的获取的时间片次数越多
 */
public class PriorityDemo {
    public static void main(String[] args) {
        Thread min = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println("min");
                }
            }
        };
        Thread max = new Thread() {
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println("max");
                }
            }
        };
        Thread norm = new Thread() {
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println("norm");
                }
            }
        };
       /* int in = min.getPriority();   默认优先级是5
        System.out.println(in);
        int i = max.getPriority();
        System.out.println(i);*/
        min.setPriority(Thread.MAX_PRIORITY);//修改优先级
        norm.setPriority(Thread.MIN_PRIORITY);
        max.setPriority(Thread.NORM_PRIORITY);
        min.start();
        max.start();
        norm.start();

    }
}

